//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_waitForRevive.sqf"
#include <btc_macros.h>
TRACE_1("Start",_this);


	_unit = player;
	BTC_r_bleeding_loop = false;
	_unit setVariable ["BTC_r_status",[1,100,1,1,1],true];
	BTC_r_damage = 0.5;
	_unit setVariable ["BTC_need_revive",1,true];
	[] spawn
	{
		waitUntil {BTC_respawn_cond || ((player getVariable "BTC_r_status") select 0 == 0 && (player getVariable "BTC_r_status") select 1 == 0 && (player getVariable "BTC_r_status") select 2 == 0 && (player getVariable "BTC_r_status") select 3 == 0)};
		player setVariable ["BTC_need_revive",0,true];
		closedialog 0;
		titleText ["", "PLAIN"];
	};
	//DEAD ANIMATION WITH RAGDOLL
	//Placeholder //player switchMove "acts_InjuredAngryRifle01"
	player switchMove "AinjPpneMstpSnonWrflDnon";
	//BTCR_pveh_killed = [10,_unit,"AinjPpneMstpSnonWrflDnon"];publicVariable "BTCR_pveh_killed";
	player setcaptive true;

	BTCR_pveh_killed = [2,_unit];publicVariable "BTCR_pveh_killed";	
	sleep 1;
	player switchMove "AinjPpneMstpSnonWrflDnon";
	WaitUntil {animationstate player == "AinjPpneMstpSnonWrflDnon"};
	_pos = getPos player;
	if (BTC_injured_marker == 1) then {BTCR_pveh_marker = [0,BTC_side,_pos,_unit];publicVariable "BTCR_pveh_marker";};
	BTC_r_timeout = time + BTC_revive_time_max;
	private ["_id","_lifes"];
	BTC_respawn_cond = false;
	//BTC_display_EH = (findDisplay 46) displayAddEventHandler ["KeyDown", "_anim = [] spawn {sleep 1;player switchMove ""AinjPpneMstpSnonWrflDnon"";};"];
	//player enableSimulation false;
	if (BTC_black_screen == 0 && BTC_disable_respawn == 0) then {
		if (BTC_action_respawn == 0) then {
			disableSerialization;
			_dlg = createDialog "BTC_respawn_button_dialog";
		} else {
			_id = player addAction [RED_TEXT("Respawn"),{(_this select 3) spawn BTCR_fnc_playerRespawn},[], 9, true, true, "", "true"];
		};
	};
	if (BTC_black_screen == 1 && BTC_disable_respawn == 0 && !Dialog) then {_dlg = createDialog "BTC_respawn_button_dialog";};
	player switchMove "AinjPpneMstpSnonWrflDnon";
	while {format ["%1", player getVariable "BTC_need_revive"] == "1" && time < BTC_r_timeout && !BTC_respawn_cond} do
	{
		//if (BTC_disable_respawn == 0) then {if (BTC_black_screen == 1 || (BTC_black_screen == 0 && BTC_action_respawn == 0)) then {if (!Dialog && !BTC_respawn_cond) then {_dlg = createDialog "BTC_respawn_button_dialog";};};};
		if (BTC_disable_respawn == 0) then {if (BTC_black_screen == 1 || (BTC_black_screen == 0 && BTC_action_respawn == 0)) then {if (!Dialog && !BTC_respawn_cond) then {_dlg = createDialog "BTC_respawn_button_dialog";};};};
		_healer = call BTCR_fnc_checkHealer;
		_lifes = "";
		if (BTC_active_lifes == 1) then {_lifes = format ["Lifes remaining: %1",BTC_lifes];};
		if (BTC_black_screen == 1) then {titleText [format ["%1\n%2\n%3", round (BTC_r_timeout - time),_healer,_lifes], "BLACK FADED"]} else {hintSilent format ["%1\n%2\n%3", round (BTC_r_timeout - time),_healer,_lifes];};
		if (format ["%1", player getVariable "BTC_need_revive"] == "0" || BTC_respawn_cond) then {closeDialog 0;};
		sleep 0.5;
	};
	//diag_log text format ["WHY!!!",""];diag_log text format ["%1 %2 %3",format ["%1", player getVariable "BTC_need_revive"] == "1" , time < BTC_r_timeout , !BTC_respawn_cond];
	closedialog 0;
	//(findDisplay 46) displayRemoveEventHandler ["KeyDown",BTC_display_EH];
	//player enableSimulation true;
	if (time > BTC_r_timeout && format ["%1", player getVariable "BTC_need_revive"] == "1") then 
	{
		player setDamage 1;
	};
	if (format ["%1", player getVariable "BTC_need_revive"] == "0" && !BTC_respawn_cond) then 
	{
		if (BTC_black_screen == 1) then {titleText ["", "BLACK IN"];} else {hintSilent "";};
		player switchMove "AinjPpneMstpSnonWnonDnon_rolltofront";
		closedialog 0;
		sleep 2;
		player playMoveNow "AmovPpneMstpSnonWnonDnon_healed";
		closedialog 0;
	};
	if (BTC_black_screen == 0 && BTC_action_respawn == 1 && BTC_disable_respawn == 0) then {_unit removeAction _id;};
	player setcaptive false;
	hintSilent "";	
